package edu.ynu.se.xiecheng.achitectureclass.dao;

import edu.ynu.se.xiecheng.achitectureclass.common.dao.LogicDAO;
import edu.ynu.se.xiecheng.achitectureclass.entity.Device;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface DeviceDao extends LogicDAO<Device, Long> {

    @Query("SELECT d FROM Device d WHERE d.isDeleted = 0 AND d.greenhouseId = :greenhouseId")
    List<Device> findByGreenhouseId(@Param("greenhouseId") Long greenhouseId);

    @Query("SELECT d FROM Device d WHERE d.isDeleted = 0 AND d.serialNumber = :serialNumber")
    Device findBySerialNumber(@Param("serialNumber") String serialNumber);

    @Query("SELECT d FROM Device d WHERE d.isDeleted = 0 AND d.serialNumber = :deviceId")
    Device findByDeviceId(@Param("deviceId") String deviceId);

    @Query("SELECT d FROM Device d WHERE d.isDeleted = 0 AND d.greenhouseId = :greenhouseId AND d.category = :category")
    List<Device> findByGreenhouseIdAndCategory(@Param("greenhouseId") Long greenhouseId, @Param("category") Integer category);

} 